package com.ruoyi.web.controller.noauth;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.service.ISysDictTypeService;

/**
 * 无需认证字典数据查询
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/noAuth/api/type")
public class NoAuthDictDataController extends BaseController
{
    @Autowired
    private ISysDictTypeService dictTypeService;

    /**
     * 查询api_server_type字典数据列表
     */
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                              @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize)
    {
        // 后端写死查询api_server_type类型的字典数据，只返回dictValue和dictLabel
        startPage();
        List<SysDictData> list = dictTypeService.selectDictDataByType("api_server_type");
        // 转换为只包含dictValue和dictLabel的简化对象
        List<java.util.Map<String, String>> simplifiedList = new java.util.ArrayList<>();
        for (SysDictData dictData : list) {
            java.util.Map<String, String> item = new java.util.HashMap<>();
            item.put("dictValue", dictData.getDictValue());
            item.put("dictLabel", dictData.getDictLabel());
            simplifiedList.add(item);
        }
        return getDataTable(simplifiedList);
    }

    /**
     * 根据字典类型查询字典数据信息（兼容原有接口）
     */
    @GetMapping("/type/api_server_type")
    public AjaxResult getApiServerType()
    {
        List<SysDictData> data = dictTypeService.selectDictDataByType("api_server_type");
        if (data == null)
        {
            data = new java.util.ArrayList<SysDictData>();
        }
        return AjaxResult.success(data);
    }
}